package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"strings"
)

func main12() {
	input := "go to study go language"
	scanner := bufio.NewScanner(strings.NewReader(input))
	split := func(data []byte, atEOF bool) (advance int, token []byte, err error) {
		// 匹配成功后，下次执行时的数据，只是在缓冲区位置前移一个字节
		if bytes.Equal(data[:2], []byte{'g', 'o'}) {
			return 1, []byte("found"), nil
		}

		if atEOF {
			return 0, nil, io.EOF
		}

		return 1, nil, nil
	}
	scanner.Split(split)
	for scanner.Scan() {
		fmt.Printf("%s\n", scanner.Text())
	}
}
